﻿using System;
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Net.Mail;
using Microsoft.Practices.Unity.Utility;

namespace NTQOnlineExam.Services.CommandService.Email
{
    public class EmailService : IEmailService
    {
        public void SendEmail(MailMessage mailMessage, bool isBodyHtml = true)
        {
            Guard.ArgumentNotNull(mailMessage, "mailMessage");
            if (mailMessage.To.Count < 1)
                throw new ValidationException("MailMessage object must contain at least an address where you want to send the message.");
            mailMessage.IsBodyHtml = isBodyHtml;

            var client = new SmtpClient();
            client.Send(mailMessage);
        }
    }
}
